package com.xjtu.platform.respondent.convert;


import com.xjtu.platform.common.CommonService;
import com.xjtu.platform.common.CurrentUser;
import com.xjtu.platform.common.Result;
import com.xjtu.platform.common.TokenUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/respondent")
public class ConvertAPI {
    @Resource
    private ConvertService convertService;

    @Resource
    private CommonService commonService;

    @RequestMapping(value = "/convert",method = RequestMethod.GET)
    public Result convertList(@RequestHeader("Token") String token){
        CurrentUser currentUser = TokenUtils.getUserInfo(token,commonService);
        Map<String,Object> page = convertService.getConvertList(currentUser);
        return Result.success(page);
    }

    @PostMapping("/convertmoney")
    public Result convertmoney(@RequestBody ConvertDto dto){
        try{
            convertService.convertMoney(dto);
            return Result.success();
        }catch(Exception e) {
            e.printStackTrace();
        }
        return Result.fail(400,"系统错误！");
    }

}
